package com.yonyou.byb.bs;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.itf.uap.IUAPQueryBS;
import nc.vo.org.StockOrgVO;
import nc.vo.pub.BusinessException;

public class OrgRuleCache {
	private Map<String,Boolean> orgRuleMap = new HashMap<>();
	
	private static OrgRuleCache instance = new OrgRuleCache();
	
	private OrgRuleCache() {
	}
	
	public static OrgRuleCache getInstance() {
		return instance;
	}
	
	public Boolean getOrgRule(String orgcode) {
		if(orgRuleMap.containsKey(orgcode)) {
			return orgRuleMap.get(orgcode);
		}
		
		synchronized (this){
			boolean isPuhuo = false;
			try {
				@SuppressWarnings("unchecked")
				List<StockOrgVO> col = (List<StockOrgVO>) NCLocator.getInstance().lookup(IUAPQueryBS.class)
						.retrieveByClause(StockOrgVO.class, "code='"+ orgcode +"'");
				if(!col.isEmpty() && col.get(0) != null) {
					isPuhuo = "Y".equals(col.get(0).getDef20());
				}
			} catch (BusinessException e) {
				Logger.error(e.getMessage(),e);
			}
			orgRuleMap.put(orgcode, new Boolean(isPuhuo));
		}
		
		return orgRuleMap.get(orgcode);
	}
	
	

}
